//
//  YZSickDetailsView.m
//  患者信息界面（代码）
//
//  Created by Yip-Jun on 16/5/9.
//  Copyright © 2016年 YIPWJ. All rights reserved.
//

#import "YZSickDetailsView.h"
#import "Masonry.h"


@interface YZSickDetailsView ()

@property (nonatomic, strong) UIView *grayView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIButton *changeButton;

@property (nonatomic, strong) UILabel *sickDescribeLabel;
@property (nonatomic, strong) NSMutableArray *describeButtons;

@property (nonatomic, strong) NSArray *describes;

@property (nonatomic, strong) UIView *topLineView;
@property (nonatomic, strong) UILabel *complicationLabel;
@property (nonatomic, strong) UILabel *complicationDescribeLabel;
@property (nonatomic, strong) UIView *bottomLineView;

@property (nonatomic, strong) UILabel *myselfMedicalLabel;
@property (nonatomic, strong) NSArray *medicals;
@property (nonatomic, strong) NSMutableArray *medicalButtons;

@end

@implementation YZSickDetailsView

+ (instancetype)sickDetailsView {
    YZSickDetailsView *sickView = [[YZSickDetailsView alloc] init];

    [sickView prepareUI];
    [sickView setSubviewsFrame];
    
    return sickView;
}

- (void)prepareUI {
    
    [self addSubview:self.grayView];
    [self.grayView addSubview:self.titleLabel];
    [self.grayView addSubview:self.changeButton];
    
    [self addSubview:self.sickDescribeLabel];
    
    [self.describes enumerateObjectsUsingBlock:^(NSString *describe, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *button = [[UIButton alloc] init];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        [button setTitle:describe forState: UIControlStateNormal];
        [button setTitleColor:[UIColor blueColor] forState: UIControlStateNormal];
        [self.describeButtons addObject:button];
        [self addSubview:button];
    }];
    
    [self addSubview:self.topLineView];
    [self addSubview:self.complicationLabel];
    [self addSubview:self.complicationDescribeLabel];
    [self addSubview:self.bottomLineView];
    
    [self addSubview:self.myselfMedicalLabel];
    [self.medicals enumerateObjectsUsingBlock:^(NSString *medical, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *button = [[UIButton alloc] init];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        [button setTitle:medical forState: UIControlStateNormal];
        [button setTitleColor:[UIColor blueColor] forState: UIControlStateNormal];
        [self.medicalButtons addObject:button];
        [self addSubview:button];
    }];
}

- (void)setSubviewsFrame {
    
    [self.grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self);
        make.height.mas_equalTo(30);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.grayView);
        make.leading.equalTo(self.grayView).offset(48);
    }];
    
    [self.changeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.grayView.mas_trailing).offset(-8);
        make.centerY.equalTo(self.grayView);
    }];
    
    [self.sickDescribeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.grayView.mas_bottom).offset(8);
        make.leading.equalTo(self).offset(16);
    }];

    UIButton *button0 = self.describeButtons[0];
    [button0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.sickDescribeLabel);
        make.leading.equalTo(self.sickDescribeLabel.mas_trailing).offset(16);
    }];

    UIButton *button1 = self.describeButtons[1];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.sickDescribeLabel);
        make.leading.equalTo(button0.mas_trailing).offset(16);
    }];
    
    UIButton *button2 = self.describeButtons[2];
    [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.sickDescribeLabel);
        make.leading.equalTo(button1.mas_trailing).offset(16);
    }];

    UIButton *button3 = self.describeButtons[3];
    [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button0.mas_bottom).offset(8);
        make.leading.equalTo(button0);
    }];

    UIButton *button4 = self.describeButtons[4];
    [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(button3);
        make.leading.equalTo(button3.mas_trailing).offset(16);
    }];

    UIButton *button5 = self.describeButtons[5];
    [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(button4);
        make.leading.equalTo(button4.mas_trailing).offset(16);
    }];

    UIButton *button6 = self.describeButtons[6];
    [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(button3.mas_bottom).offset(8);
        make.leading.equalTo(button3);
    }];

    [self.topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.grayView.mas_bottom).offset(300);
        make.leading.equalTo(self).offset(8);
        make.trailing.equalTo(self).offset(-8);
        make.height.mas_equalTo(1);
    }];
    
    [self.complicationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topLineView).offset(8);
        make.leading.equalTo(self.topLineView);
    }];
    
    [self.complicationDescribeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.complicationLabel);
        make.leading.equalTo(self.complicationLabel.mas_trailing).offset(8);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.complicationLabel.mas_bottom).offset(8);
        make.leading.equalTo(self).offset(8);
        make.trailing.equalTo(self).offset(-8);
        make.height.mas_equalTo(1);
    }];
    
    [self.myselfMedicalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomLineView.mas_bottom).offset(8);
        make.leading.equalTo(self.bottomLineView);
    }];
    
    UIButton *medicalButton0 = self.medicalButtons[0];
    [medicalButton0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.myselfMedicalLabel);
        make.leading.equalTo(self.myselfMedicalLabel.mas_trailing).offset(32);
    }];
    
    UIButton *medicalButton1 = self.medicalButtons[1];
    [medicalButton1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.myselfMedicalLabel);
        make.leading.equalTo(medicalButton0.mas_trailing).offset(16);
    }];
    
    UIButton *medicalButton2 = self.medicalButtons[2];
    [medicalButton2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.myselfMedicalLabel);
        make.leading.equalTo(medicalButton1.mas_trailing).offset(16);
    }];
    
    UIButton *medicalButton3 = self.medicalButtons[3];
    [medicalButton3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(medicalButton0.mas_bottom).offset(8);
        make.leading.equalTo(medicalButton0);
    }];

    
}

- (void)changeButtonDidClick {
    self.changeButtonDidClickBlock();
}

#pragma mark - 懒加载
- (UIView *)grayView {
    if (!_grayView) {
        _grayView = [[UIView alloc] init];
        _grayView.backgroundColor = [UIColor lightGrayColor];
    }
    return _grayView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.text = @"疾病详情";
    }
    return _titleLabel;
}

- (UIButton *)changeButton {
    if (!_changeButton) {
        _changeButton = [[UIButton alloc] init];
        [_changeButton addTarget:self action:@selector(changeButtonDidClick) forControlEvents: UIControlEventTouchUpInside];
        [_changeButton setTitle:@"选择已有病例" forState: UIControlStateNormal];
        [_changeButton setTitleColor:[UIColor colorWithRed:(0 / 255.0) green:(122 / 255.0) blue:(255 / 255.0) alpha:1]  forState: UIControlStateNormal];
    }
    return _changeButton;
}

- (UILabel *)sickDescribeLabel {
    if (!_sickDescribeLabel) {
        _sickDescribeLabel = [[UILabel alloc] init];
        _sickDescribeLabel.text = @"疾病描述：";
        _sickDescribeLabel.font = [UIFont systemFontOfSize:18];
    }
    return _sickDescribeLabel;
}

//- (UIButton *)describeButton {
//    if (!_describeButton) {
//        _describeButton = [[UIButton alloc] init];
//    }
//    return _describeButton;
//}

- (NSMutableArray *)describeButtons {
    if (!_describeButtons) {
        _describeButtons = [NSMutableArray array];
    }
    return _describeButtons;
}

- (NSArray *)describes {
    if (!_describes) {
        _describes = [NSArray arrayWithObjects:@"腹痛", @"厌食", @"乏力", @"体重减轻", @"恶心", @"呕吐", @"呕血", nil];
    }
    return _describes;
}

- (UIView *)topLineView {
    if (!_topLineView) {
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = [UIColor blackColor];
    }
    return _topLineView;
}

- (UILabel *)complicationLabel {
    if (!_complicationLabel) {
        _complicationLabel = [[UILabel alloc] init];
        _complicationLabel.text = @"并发症状：";
    }
    return _complicationLabel;
}

- (UILabel *)complicationDescribeLabel {
    if (!_complicationDescribeLabel) {
        _complicationDescribeLabel = [[UILabel alloc] init];
        _complicationDescribeLabel.text = @"暂无并发症状";
    }
    return _complicationDescribeLabel;
}

- (UIView *)bottomLineView {
    if (!_bottomLineView) {
        _bottomLineView = [[UIView alloc] init];
        _bottomLineView.backgroundColor = [UIColor blackColor];
    }
    return _bottomLineView;
}

- (UILabel *)myselfMedicalLabel {
    if (!_myselfMedicalLabel) {
        _myselfMedicalLabel = [[UILabel alloc] init];
        _myselfMedicalLabel.text = @"个人史：";
    }
    return _myselfMedicalLabel;
}

- (NSArray *)medicals {
    if (!_medicals) {
        _medicals = [NSArray arrayWithObjects:@"有家族病史", @"吸烟", @"饮酒", @"喜咸食物", nil];
    }
    return _medicals;
}

- (NSMutableArray *)medicalButtons {
    if (!_medicalButtons) {
        _medicalButtons = [NSMutableArray array];
    }
    return _medicalButtons;
}

@end

